<?php
/**
 * 前端输出类
 * @author 41412754@qq.com
 */
class html {
	
	public function selectOptions( array $options, $selectedItems = null )
	{
		if ( empty( $options ) ) return false;
		$selectedItems = ",$selectedItems,";
		foreach ( $options as $key => $value )
		{
			#$key = str_replace( 'item', '', $key );
			$selected = strpos( $selectedItems, ",$key," ) !== false ? ' selected="selected"' : '';
			$string .= "<option value=\"$key\"$selected>$value</option>\n";
		}
		return $string;
	}
	
	public function js( $str )
	{
		echo '<script type="text/javascript">' . $str . '</script>';
	}
}

class js {
	
	public static function import( $url, $version = null )
	{
		$GLOBALS['app']->front->js->import[] = "$url?v=$version";
	}
	
	public static function export()
	{
		$urls = &$GLOBALS['app']->front->js->import;
		if ( ! is_array( $urls ) ) return false;
		foreach ( $urls as $url )
		{
			echo '<script type="text/javascript" src="' . $url . '"></script>' . "\n";
		}
	}
}

class css {
	
	public static function import( $url, $version = null )
	{
		$GLOBALS['app']->front->css->import[] = "$url?v=$version";
	}
	
	public static function export()
	{
		$urls = &$GLOBALS['app']->front->css->import;
		if ( ! is_array( $urls ) ) return false;
		foreach ( $urls as $url )
		{
			echo '<link rel="stylesheet" type="text/css" media="screen" href="' . $url . '" />' . "\n";
		}
	}
}